package demo;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Comparator;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;

@Path("/read")
public class ReadController extends Controller {
	public void index() {
    	render("read.html");
    }
	
	public void list(){
		String path=getRequest().getServletContext().getRealPath("/")+"\\"+"book";
		File file = new File(path);
		String[] fileList = file.list(); 
		JSONArray data=new JSONArray();
		for (String fileName : fileList) {
		    File subFile = new File(file.getPath() + "\\" + fileName);
		    if(subFile.isDirectory()){ 
		    	JSONObject jo=new JSONObject().parseObject("{'name':'"+subFile.getName()+"'}");
		        data.add(jo);
		    }
		}
		renderJson((JSONObject) JSONObject.parse("{'res':'ok','data':"+data.toJSONString()+"}"));
	}
	
	public void read(){
		String jsonData = getRawData();
    	JSONObject jo = JSONObject.parseObject(jsonData);
    	String bookname=jo.getString("name");
    	System.out.println(bookname);
		render("book/index");
		
	}
	
	
}
